n = 23.23232
"{:.3f}".format(n)
'23.232'
print(f"{n:.2f}")
23.23
def celsius_to_fahrenheit(celsius):
fahrenheit = (celsius * 9/5) + 32
return fahrenheit
# Example usage:
celsius_value = 25
fahrenheit_value = celsius_to_fahrenheit(celsius_value)
print(f"{celsius_value} degrees Celsius is equal to {fahrenheit_value} degrees Fahrenheit.")
25 degrees Celsius is equal to 77.0 degrees Fahrenheit.
def fahrenheit_to_celsius(fahrenheit):
celsius = (fahrenheit - 32) * 5/9
return celsius
# Example usage:
fahrenheit_value = 77
celsius_value = fahrenheit_to_celsius(fahrenheit_value)
print(f"{fahrenheit_value} degrees Fahrenheit is equal to {celsius_value} degrees Celsius.")
77 degrees Fahrenheit is equal to 25.0 degrees Celsius.
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def print_primes_between(start, end):
print(f"Prime numbers between {start} and {end}:")
for num in range(start, end + 1):
if is_prime(num):
print(num)
# Example usage:
start_num = 10
end_num = 30
print_primes_between(start_num, end_num)
start = 10
end = 30
print(f"Prime numbers between {start} and {end}:")
for num in range(start, end + 1):
if num > 1:
is_prime = True
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num)
limit = 30
prime = [True for _ in range(limit + 1)]
p = 2
while p * p <= limit:
if prime[p] == True:
for i in range(p * p, limit + 1, p):
prime[i] = False
p += 1
primes = [p for p in range(2, limit + 1) if prime[p]]
print(f"Prime numbers up to {limit}:")
print(primes)
decimal_number = 25
binary = []
if decimal_number == 0:
binary.append(0)
else:
while decimal_number > 0:
binary.append(decimal_number % 2)
decimal_number //= 2
binary.reverse() # Reverse the list to get the binary representation
binary_str = ''.join(map(str, binary))
print(f"The binary representation of {decimal_number} is: {binary_str}")
triange = []
for i in range(6):
row = []
for j in range(i+1):
if j == 0 or j == i:
row.append(1)
else:
x = triange[i-1][j-1] + triange[i-1][j]
row.append(x)
triange.append(row)
print(triange)
n = len(triange)
print(n)
for i in range(n):
for j in range(n-1-i):
print(" ", end="")
for j in range(i + 1):
print(triange[i][j], end=" ")
print()
triange = []
for i in range(16):
row = []
for j in range(i+1):
if j == 0 or j == i:
row.append(1)
else:
x = triange[i-1][j-1]+triange[i-1][j]
row.append(x)
triange.append(row)
n = len(triange)
for i in range(n):
for j in range(n - 1 - i):
print(" ", end="")
for j in range(i + 1):
print(triange[i][j], end=" ")
print()
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
1 11 55 165 330 462 462 330 165 55 11 1
1 12 66 220 495 792 924 792 495 220 66 12 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1
1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1
max_width = len(" ".join(map(str, triange[-1])))
# Loop to print each row of the triangle
for row in triange:
row_str = " ".join(map(str, row))
# Center-align the row within the maximum width for a nicer display
print(row_str.center(max_width))
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
1 11 55 165 330 462 462 330 165 55 11 1
1 12 66 220 495 792 924 792 495 220 66 12 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1
1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1
rows = 5 # Define the number of rows for Floyd's Triangle
number = 1
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(number, end=" ")
number += 1
print()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15